package com.sse.product.rbac.entity;

import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.security.core.GrantedAuthority;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.io.Serializable;

/**
 * <p>
 *
 * </p>
 *
 * @author junyongli
 * @since 2022-07-22
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("rbac_menus")
public class Menus implements Serializable, GrantedAuthority {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    @NotNull(message = "菜单的id不能为空")
    private Long id;

    @NotEmpty(message = "菜单的名称(uniqueName)不能为空!")
    @Pattern(regexp = "^[\\u4E00-\\u9FA5A-Za-z0-9_]+$", message = "菜单的名称只能包含中英文数字下划线")
    private String uniqueName; //唯一名,不可重复；也是权限判断的基础

    private String name;

    private String type;  // 功能类型：menu-菜单类，permission-权限控制类
    /**
     * 逻辑删除字段
     */
    @TableLogic(value = "0", delval = "1")
    @TableField(value = "delete_flag", fill = FieldFill.INSERT)
    private String deleteFlag = "0";

    @Override
    public String getAuthority() {
        return uniqueName;
    }
}
